import { _detail, _handle } from '../../common/passcard'
import { _getQr } from '../../common/getQr'
import { formatDate } from '../../utils/util'
const app = getApp()
const date = new Date()
const today = date.getFullYear() + '/' + (date.getMonth() + 1) + '/' + date.getDate()
// const today = '2019/12/30'
Page({
  data: {
    id: null,
    role: '',
    detail: {},
    handleBoxShow: false,
    type: null,
    remark: '',
    passImg: '',
    imgArr: []
  },
  getDetail() {
    app.loading('加载中')
    _detail(this.data.id).then(res => {
      wx.hideLoading()
      let detail = res.data.ERelease_Apply
      // 是否可重新提交
      detail.again = this.data.role === "租户" && detail.Status.includes("拒绝")
      detail.showBtns = detail.Status !== '已放行' && !detail.Status.includes('拒绝')
      detail.Goods = JSON.parse(detail.Goods)
      detail.guardShow = detail.OrderTime && formatDate(new Date(detail.OrderTime), 'yyyy/MM/dd')
      detail.guardShow = new Date(detail.guardShow).getTime() === new Date(today).getTime()
      detail.CompanyAuditTime = detail.CompanyAuditTime && formatDate(new Date(detail.CompanyAuditTime), 'yyyy年MM月dd日')
      detail.OrderTime = detail.OrderTime && formatDate(new Date(detail.OrderTime), 'yyyy年MM月dd日')
      detail.AuditTime = detail.AuditTime && formatDate(new Date(detail.AuditTime), 'yyyy年MM月dd日')
      detail.PassTime = detail.PassTime && formatDate(new Date(detail.PassTime), 'yyyy年MM月dd日')
      detail.PassImg = detail.PassImg ? JSON.parse(detail.PassImg) : []
      detail.qr = _getQr(detail.SN)
      this.setData({
        detail
      })
    }).catch(err => {
      wx.hideLoading()
      wx.showModal({
        title: '对不起',
        content: '请求失败，请稍后再试',
        showCancel: false
      })
    })
  },
  onLoad(options) {
    this.data.id = options.id
    this.setData({
      id: this.data.id
    })
  },
  onReady() { },
  onShow() {
    app.memberReadyCb = () => {
      this.getDetail()
    }
    app.fansReadyCb = () => {
      app.checkMember()
    }
    app.init()
  },
  onHide() { },
  onUnload() { },
  onShareAppMessage() {
    return app.shareInfo
  }
})